// pages/my_care/adv_success.js
var app = getApp();
var that
Page({

  data: {
    ordersn:'',
    my_cat:'', //我的猫咪
    order:'', //这份订单 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that=this;
    console.log(options)
    if (options.ordersn) { that.setData({ ordersn: options.ordersn})}

    // that.get_order(); //成功之后获取猫
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () { 
    that.get_order() //成功之后获取猫
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  to_addcat:function(){
    wx:wx.navigateTo({
      url: '../cat_mse/cat_mse'
    })
  },

  to_order:function(){
    wx.redirectTo({
      url: '../advance/advance?ordersn=' + that.data.ordersn
    })
  },
  get_cat: function () {
    app.req("get_mycatnum.html", {  "openid": app.data.openid }, function (res) {
      if (res.status == "success") {     //获取猫的信息
        that.setData({ my_cat: res.mess });
        // if (res.mess.length<that.data.order.cat.length){ //当猫咪数量小于住房猫数
        //   that.setData({ my_cat: res.mess });
        // }
      } else {
        app.modal("错误提示", "网络错误，是否重试？", function (re) {
          if (re) {
            that.get_cat()
          }
        })
      }
    })
  },
  get_order:function(){
    app.req("get_orderroom.html", { "openid": app.data.openid, "ordersn": that.data.ordersn }, function (res) {
      console.log(res)
      if (res.status == "success") {
        that.get_cat(); //获取完订单就获取猫
        that.setData({order:res.mess})
      } else if (res.status == "error") {
        app.toast_up(res.mess)
      } else {
        app.modal("错误提示", "网络错误，是否重试？", function (re) {
          if (re) {
            that.get_order()
          }
        })
      }
    })
  }
})